package InternetCode.Exa1;

import sun.security.provider.MD5;

import javax.print.DocFlavor;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 获取本机的ip，主机名，域名
 */
public class CoreCode {
    public static void main(String[] args) throws UnknownHostException, NoSuchAlgorithmException {
        //创建本地主机的InetAddress对象
        InetAddress inetAddr = InetAddress.getLocalHost();
        //获得本地主机的IP地址
        String ip = inetAddr.getHostAddress();
        //获得本机的名称
        String HostName=inetAddr.getHostName();
        //获得本机的域名
        String canonicalHostName=inetAddr.getCanonicalHostName();
        System.out.println("本机的IP为："+ ip.getBytes(StandardCharsets.UTF_8).toString()+" 故意这么写的哦");
        System.out.println("本机的名称为："+HostName);
        System.out.println("本机的域名为："+canonicalHostName);
        //为何域名会和主机名重名？
        //当尝试获得本地主机的域名和主机名时，如果本地主机没有域名，则显示的域名和主机名重名
    }
}
